package com.seednia.foundation.framework.dto;

import javax.persistence.Column;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import com.seednia.foundation.framework.dto.annotation.IndexableField;
import com.seednia.module.core.project.dto.ProjectDto;
import com.seednia.module.core.tagging.dto.AbstractTaggableRecord;
import com.seednia.module.core.user.dto.UserDto;

/**
 * Abstract Class for all the DTOs that are Content. For example Post.
 * 
 * @author Young Suk Ahn
 *
 */
@XmlRootElement(name = "ContentDto", 
namespace = "http://seednia.com/foundation/1.0")
@XmlType(name = "ContentDto")
@XmlAccessorType(XmlAccessType.PROPERTY)
@JsonIgnoreProperties({ "creatorDto",  "projectDto" }) // For jackson
public class ContentDto extends AbstractTaggableRecord {
	
	public static final int STATE_DRAFT = 0;
	public static final int STATE_REVIEWED = 1;
	public static final int STATE_PUBLISHED = 2;
	public static final int STATE_DELETED = -1;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3410971716205277910L;
	
	private String uuid = null; /* GUID (assigned by system)  */
	private int state = 0; /* state: 0=draft, 1=reviewed, 2=published, -1=deleted  */ 
	//private Long projectSid = null; /* The project this Log belongs to  */
	
	private String type = null; /* Type:   */ 
	private String subject = null; /* The main content  */ 
	private String body = null; /* The main content  */ 
	private String mediaUrl = null; /* remote media (image/video) URL  */ 
	private String mediaType = null; /* remote media type: image, video, audio  */ 
	private String mediaTitle = null; /* remote media Title  */ 
	private int thumbnailWidth = 0; /* thumbnail image width  */ 
	private int thumbnailHeight = 0; /* thumbnail image height  */ 
	private int privacyLevel = 0; /* Visibility scope: 0=public,   */ 
	private int numComments = 0; /* Number of comments  */ 
	private int numCheers = 0; /* Number of likes  */ 

	private com.seednia.module.core.user.dto.UserDto creatorDto = null; /* The author of the post  */
	private com.seednia.module.core.project.dto.ProjectDto projectDto = null; /* Project.  */ 
	
	public ContentDto()
	{
		super(); // AbstractTagging
	}

	@Override
	public Long getCreatorSid() {
		return creatorDto != null ? creatorDto.getSid() : null;
	}
	public void setCreatorSid(long creatorSid) {
		if (creatorDto == null){
			creatorDto = new UserDto();
		}
		creatorDto.setSid(creatorSid);
	}
	
	@Override
	public String getCreatorId() {
		return creatorDto != null ? creatorDto.getId() : null;
	}
	public String getCreatorDisplayName() {
		return creatorDto != null ? creatorDto.getDisplayName() : null;
	}
	public Long getCreatorProfileImageSid() {
		return creatorDto != null ? creatorDto.getProfileImageSid() : null;
	}


	@Column(updatable = false, name = "uuid", nullable = false, length=64)
	@IndexableField(store=IndexableField.Store.YES)
	public String getUuid() {
		return uuid;
	}
	public void setUuid(String uuid) {
		//String old = this.uuid;
        //this.vcs.fireVetoableChange( "uuid", old, uuid );
		this.uuid = uuid;
        //this.pcs.firePropertyChange( "uuid", old, uuid );
	}
	
	public int getState() {
		return state;
	}
	@IndexableField(store=IndexableField.Store.YES)
	public void setState(int state) {
		//int old = this.state;
        //this.vcs.fireVetoableChange( "state", old, state );
		this.state = state;
        //this.pcs.firePropertyChange( "state", old, state );
	}

	/*
	@IndexableField(store=IndexableField.Store.YES)
	public Long getProjectSid() {
		return projectSid;
	}
	public void setProjectSid(Long projectSid) {
		//Integer old = this.projectSid;
        //this.vcs.fireVetoableChange( "projectSid", old, projectSid );
		this.projectSid = projectSid;
        //this.pcs.firePropertyChange( "projectSid", old, projectSid );
	}*/

	@IndexableField(store=IndexableField.Store.YES)
	public String getType() {
		return type;
	}
	public void setType(String type) {
		//String old = this.type;
        //this.vcs.fireVetoableChange( "type", old, type );
		this.type = type;
        //this.pcs.firePropertyChange( "type", old, type );
	}
	
	@IndexableField(store=IndexableField.Store.YES)
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		//String subject = this.subject;
        //this.vcs.fireVetoableChange( "subject", old, subject );
		this.subject = subject;
        //this.pcs.firePropertyChange( "subject", old, subject );
	}

	@IndexableField(store=IndexableField.Store.YES)
	public String getBody() {
		return body;
	}
	public void setBody(String body) {
		//String old = this.body;
        //this.vcs.fireVetoableChange( "body", old, body );
		this.body = body;
        //this.pcs.firePropertyChange( "body", old, body );
	}
	
	public String getMediaUrl() {
		return mediaUrl;
	}
	public void setMediaUrl(String mediaUrl) {
		//String old = this.mediaUrl;
        //this.vcs.fireVetoableChange( "mediaUrl", old, mediaUrl );
		this.mediaUrl = mediaUrl;
        //this.pcs.firePropertyChange( "mediaUrl", old, mediaUrl );
	}
	
	public String getMediaType() {
		return mediaType;
	}
	public void setMediaType(String mediaType) {
		//String old = this.mediaType;
        //this.vcs.fireVetoableChange( "mediaType", old, mediaType );
		this.mediaType = mediaType;
        //this.pcs.firePropertyChange( "mediaType", old, mediaType );
	}
	
	public String getMediaTitle() {
		return mediaTitle;
	}
	public void setMediaTitle(String mediaTitle) {
		//String old = this.mediaTitle;
        //this.vcs.fireVetoableChange( "mediaTitle", old, mediaTitle );
		this.mediaTitle = mediaTitle;
        //this.pcs.firePropertyChange( "mediaTitle", old, mediaTitle );
	}
	
	public int getThumbnailWidth() {
		return thumbnailWidth;
	}
	public void setThumbnailWidth(int thumbnailWidth) {
		//int old = this.thumbnailWidth;
        //this.vcs.fireVetoableChange( "thumbnailWidth", old, thumbnailWidth );
		this.thumbnailWidth = thumbnailWidth;
        //this.pcs.firePropertyChange( "thumbnailWidth", old, thumbnailWidth );
	}
	
	public int getThumbnailHeight() {
		return thumbnailHeight;
	}
	public void setThumbnailHeight(int thumbnailHeight) {
		//int old = this.thumbnailHeight;
        //this.vcs.fireVetoableChange( "thumbnailHeight", old, thumbnailHeight );
		this.thumbnailHeight = thumbnailHeight;
        //this.pcs.firePropertyChange( "thumbnailHeight", old, thumbnailHeight );
	}
	
	@IndexableField(store=IndexableField.Store.YES)
	public int getPrivacyLevel() {
		return privacyLevel;
	}
	public void setPrivacyLevel(int privacyLevel) {
		//int old = this.privacyLevel;
        //this.vcs.fireVetoableChange( "privacyLevel", old, privacyLevel );
		this.privacyLevel = privacyLevel;
        //this.pcs.firePropertyChange( "privacyLevel", old, privacyLevel );
	}
	
	
	public int getNumComments() {
		return numComments;
	}
	public void setNumComments(int numComments) {
		//int old = this.numComments;
        //this.vcs.fireVetoableChange( "numComments", old, numComments );
		this.numComments = numComments;
        //this.pcs.firePropertyChange( "numComments", old, numComments );
	}
	
	public int getNumCheers() {
		return numCheers;
	}
	public void setNumCheers(int numCheers) {
		//int old = this.numCheers;
        //this.vcs.fireVetoableChange( "numCheers", old, numCheers );
		this.numCheers = numCheers;
        //this.pcs.firePropertyChange( "numCheers", old, numCheers );
	}


	// Many-to-one mappings:
	public com.seednia.module.core.user.dto.UserDto getCreatorDto() {
		return creatorDto;
	}
	public void setCreatorDto(com.seednia.module.core.user.dto.UserDto creatorDto) {
		//com.seednia.module.core.user.dto.UserDto old = this.creatorDto;
        //super.vcs.fireVetoableChange( "creatorDto", old, creatorDto );
		this.creatorDto = creatorDto;
        //super.pcs.firePropertyChange( "creatorDto", old, creatorDto );
	}
	
	@XmlTransient // We do not need to export the whole project info, just the id and name
	public com.seednia.module.core.project.dto.ProjectDto getProjectDto() {
		return projectDto;
	}
	public void setProjectDto(com.seednia.module.core.project.dto.ProjectDto projectDto) {
		//com.seednia.module.core.project.dto.ProjectDto old = this.projectDto;
        //super.vcs.fireVetoableChange( "projectDto", old, projectDto );
		this.projectDto = projectDto;
        //super.pcs.firePropertyChange( "projectDto", old, projectDto );
	}
	
	@IndexableField(store=IndexableField.Store.YES)
	public Long getProjectSid() {
		return (this.projectDto != null) ? projectDto.getSid() : null;
	}
	public void setProjectSid(Long projectSid) {
		if (this.projectDto == null){
			this.projectDto = new ProjectDto();
		}
		this.projectDto.setSid(projectSid);
	}
	
	@IndexableField(store=IndexableField.Store.YES)
	public String getProjectId() {
		return (projectDto != null) ? projectDto.getId() : null;
	}
	/**
	 * Used for Search retrieval
	 * @param projectName
	 */
	public void setProjectId(String projectId) {
		if (this.projectDto == null){
			this.projectDto = new ProjectDto();
		}
		this.projectDto.setId(projectId);
	}

	public String getProjectName() {
		return (projectDto != null) ? projectDto.getName() : null;
	}
	/**
	 * Used for Search retrieval
	 * @param projectName
	 */
	public void setProjectName(String projectName) {
		if (this.projectDto == null){
			this.projectDto = new ProjectDto();
		}
		this.projectDto.setId(projectName);
	}

}
